package by_book_java_DXCBCHXJS.wait_notify;

/**
 * @author fengwenxiang
 * @date 2022/2/9 16:43
 * @description
 */
public class WaitAndNotify02 {
    static class Wait_Notify_Thread implements Runnable{
        @Override
        public void run() {
            synchronized (this){
                try {
                    for (int i = 0; i < 5; i++) {
                        System.out.println(Thread.currentThread().getName()+" = "+i);
                        this.notify();
                        this.wait();
                    }
                }catch (Exception e){

                }
                this.notify();
            }
        }
    }

    public static void main(String[] args) {
        Wait_Notify_Thread wait_notify_thread = new Wait_Notify_Thread();
        new Thread(wait_notify_thread,"AA").start();
        new Thread(wait_notify_thread,"BB").start();
    }
}
